package cn.kgc.brand.controller;

import cn.kgc.brand.service.BrandService;
import cn.kgc.common.entity.Brand;
import cn.kgc.common.entity.DataPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BrandController {
    @Autowired
    private BrandService brandService;

    @GetMapping("/brands")
    public DataPage<Brand> listBrand(@RequestParam Integer pageNum,
                                     @RequestParam Integer pageSize){
        //分页信息
        Page<Brand> pageInfo = new Page<>(pageNum, pageSize);

        //分页查询
        Page<Brand> page = brandService.page(pageInfo);

        //数据转换
        DataPage dataPage = new DataPage();
        dataPage.setDataList(page.getRecords());
        dataPage.setRowCount((int)page.getTotal());
        dataPage.setPageCount((int)page.getPages());
        dataPage.setPageNum(pageNum);
        dataPage.setPageSize(pageSize);

        return dataPage;
    }


}
